package com.bestcem.xm.label.dao;

import com.bestcem.xm.common.core.uitls.DateUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;

/**
 * mongo 实体基类, collection 通用字段
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/5/8
 */
@ToString
@Getter
@Setter
public abstract class BaseEntity implements Serializable {
    private static final long serialVersionUID = 8603603434168439276L;

    //    @MongoId(targetType = FieldType.OBJECT_ID)
    protected String id;

    /**
     * 数据记录标记
     */
    //    @Fiel("record_flag")
    protected Integer recordFlag = 1;

    //    @Fiel("created_dt")
    protected Date createdDate;

    //    @Fiel("created_id")
    protected String createdId;

    //    @Fiel("updated_dt")
    protected Date updatedDate;

    //    @Fiel("updated_id")
    protected String updatedId;

    public Date getCreatedDate() {
        if (Objects.nonNull(this.createdDate)) {
            LocalDateTime localDateTime = this.createdDate.toInstant().atZone(DateUtil.SELECT_ZONE).toLocalDateTime();
            return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        }
        return null;
    }

    public Date getUpdatedDate() {
        if (Objects.nonNull(this.updatedDate)) {
            LocalDateTime localDateTime = this.updatedDate.toInstant().atZone(DateUtil.SELECT_ZONE).toLocalDateTime();
            return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        }
        return null;
    }

}
